package com.example.hangman_in_android.view;

import com.example.hangman_in_android.R;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.EditText;

public class OptionMenuActivity extends Activity implements OnClickListener {

	// buttons
	Button buttonStart;

	// EditTexts
	EditText playerOneName;
	EditText playerTwoName;

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_option_menu);

		// buttons
		buttonStart = (Button) findViewById(R.id.buttonStart);
		buttonStart.setOnClickListener(this);

		// EditTexts
		playerOneName = (EditText) findViewById(R.id.ETplayerOneName);
		playerTwoName = (EditText) findViewById(R.id.ETplayerTwoName);
	}

	public void onClick(View v) {
		Intent intent;
		if (v == buttonStart) {
			intent = new Intent(this, BoardActivity.class);
			if (getPlayerOneName().isEmpty() & getPlayerTwoName().isEmpty()) {
				intent.putExtra("playerOneName", "Player 1");
				intent.putExtra("playerTwoName", "Player 2");

			} else if (getPlayerOneName().isEmpty()
					& !getPlayerTwoName().isEmpty()) {

				intent.putExtra("playerOneName", "Player 1");
				intent.putExtra("playerTwoName", getPlayerTwoName());
			} else if (!getPlayerOneName().isEmpty()
					& getPlayerTwoName().isEmpty()) {
				intent.putExtra("playerOneName", getPlayerOneName());
				intent.putExtra("playerTwoName", "Player 2");

			} else {
				intent.putExtra("playerOneName", getPlayerOneName());
				intent.putExtra("playerTwoName", getPlayerTwoName());

			}
			startActivity(intent);
		} else {
			System.out.println("ERROR");
		}

	}

	/**
	 * 
	 * @return player one Name
	 */
	public String getPlayerOneName() {
		return playerOneName.getText().toString();
	}

	/**
	 * 
	 * @return player two Name
	 */
	public String getPlayerTwoName() {
		return playerTwoName.getText().toString();
	}

}
